package com.wgo.precise.client.ui.view.editor.history;

import java.lang.reflect.Method;

import com.wgo.precise.client.compability.CommandHistory;
import com.wgo.precise.client.ui.model.facade.ILabelProviderItem;
import com.wgo.precise.client.ui.view.util.ReflectionHelper;

public enum HistoryColumnProperties {
	
	User ("getUserName", 100)
	,
	Date ("getDate", 110)
	,
	Property ("getMethod" , 100)
	,
	Value ("getArgument" , 150)
	;

	private Method getValueMethod = null;
	private int width = 0;
	
	private HistoryColumnProperties ( String methodName , int width) {
		getValueMethod = ReflectionHelper.retrieveMethod("Could not retrieve method with name", CommandHistory.class, methodName);
		this.width = width ;
	}
	
	public String getValue (CommandHistory cmdHist ) {
		Object value = ReflectionHelper.invoke("Could not invoke method..",cmdHist, getValueMethod) ;
		if (value instanceof ILabelProviderItem) {
			return ((ILabelProviderItem)value).getSimpleName();
		}
		return "" + value;
	}
		
	public static String[] names() {
		String[] names = new String [values().length];
		for (HistoryColumnProperties prop : values()){
			names[prop.ordinal()] = prop.name();
		}
		return names;
	}

	public int width() {
		return width;
	}
}

